/*
 * > /*
>  * INSANE - Interactive Structural Analysis Environment
>  *
>  * Copyright (C) 2003-2004
>  * Universidade Federal de Minas Gerais
>  * Escola de Engenharia
>  * Departamento de Engenharia de Estruturas
>  *
>  * Author's email :     insane@dees.ufmg.br
>  * Author's Website :   http://www.dees.ufmg.br/insane
>  *
>  * This program is free software; you can redistribute it and/or
>  * modify it under the terms of the GNU General Public License
>  * as published by the Free Software Foundation; either version 2
>  * of the License, or any later version.
>  *
>  * This program is distributed in the hope that it will be useful,
>  * but WITHOUT ANY WARRANTY; without even the implied warranty of
>  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
>  * GNU General Public License for more details.
>  *
>  * You should have received a copy of the GNU General Public License
>  * along with this program; if not, write to the Free Software
>  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-
> 1307, USA.
 *
 */

package br.ufmg.dees.insane.util;

import java.awt.Point;
import java.awt.geom.Point2D;
import java.io.Serializable;

/**A 3 element point that is represented by double precision floating point x,y,z coordinates.
* @author Fonseca, Flavio & Pitangueira, Roque
* @since May 2004
*/
public class IPoint3d implements Serializable, Cloneable {
	
	/**
	 * Comment for <code>serialVersionUID</code>
	 */
	private static final long serialVersionUID = 1L;

	/**The x coordinate.*/
	public double x = 0;
	
	/**The y coordinate.*/
	public double y = 0;
	
	/**The z coordinate.*/
	public double z = 0;
	
//*****************************************************************************
	
	/**Constructs and initializes a IPoint3d to (0,0,0).*/
	public IPoint3d() {
		x = 0;
		y = 0;
		z = 0;
	}

//*****************************************************************************
	
	/**Constructs and initializes a IPoint3d to (0,0,0).*/
	public IPoint3d(Point2D p) {
		x = p.getX();
		y = p.getY();
		z = 0;
	}

//*****************************************************************************
	
	/**Constructs and initializes a IPoint3d to (0,0,0).*/
	public IPoint3d(Point p) {
		x = p.getX();
		y = p.getY();
		z = 0;
	}
	
//*****************************************************************************
	
	/**Constructs and initializes a IPoint3d from the array of length 3.
	* @param p the array of length 3 containing xyz in order
	*/
	public IPoint3d(double[] p) {
		x = p[0];
		y = p[1];
		z = p[2];
	}
	
//*****************************************************************************
	
	/**Constructs and initializes a IPoint3d from the specified xyz coordinates.
	*@param x the x coordinate
	*@param y the y coordinate
	*@param z the z coordinate
	*/
	public IPoint3d(double x, double y, double z) {
		this.x = x;
		this.y = y;
		this.z = z;
	}
//  *****************************************************************************
    
    /**Constructs and initializes a IPoint3d from the specified xyz coordinates.
    *@param x the x coordinate
    *@param y the y coordinate
    *@param z the z coordinate
    */
    public IPoint3d(double x, double y) {
        this.x = x;
        this.y = y;
        this.z = 0;
    }	
//*****************************************************************************
	
	/**Constructs and initializes a IPoint3d from the specified IPoint3d.
	*@param p1 the IPoint3d containing the initialization x y z data
	*/
	public IPoint3d(IPoint3d p1) {
		this.x = p1.x;
		this.y = p1.y;
		this.z = p1.z;
	}
	
//*****************************************************************************
	/** Returns the coord x of this point.
	 *  @return The coord x of this point.
	 */
	public double getX(){
  	
  		return x;
  	
  		}

//*****************************************************************************
	/** Returns the coord y of this point.
	 *  @return The coord y of this point.
	 */
	public double getY(){
  		
  		return y;
  	
  		}

//*****************************************************************************
	/** Returns the coord z of this point.
	 *  @return The coord z of this point.
	 */
  	public double getZ(){
  	
  		return z;
  	
  		}

//*****************************************************************************
  	/** Returns the coords of this point.
	 *  @return The coords x, y, z of this point.
	 */
  	public double[] getCoords(){
  		double[] coords = {this.getX(), this.getY(), this.getZ()};
  		return coords;
  		}

//*****************************************************************************
	
	/**Returns the distance between this point and point p1.
	* @param p1 the other point
	* @return the distance
	*/
	public final double distance(IPoint3d p1) {
		double x2 = Math.pow(this.x - p1.x, 2);
		double y2 = Math.pow(this.y - p1.y, 2);
		double z2 = Math.pow(this.z - p1.z, 2);
		double sum = x2 + y2 + z2;
		return Math.sqrt(sum);
	}
	
//*****************************************************************************
	
	/**Returns the square of the distance between this point and point p1.
	* @param p1 the other point
	* @return the square of the distance
	*/
	public final double distanceSquared(IPoint3d p1) {
		double x2 = Math.pow(this.x - p1.x, 2);
		double y2 = Math.pow(this.y - p1.y, 2);
		double z2 = Math.pow(this.z - p1.z, 2);
		double sum = x2 + y2 + z2;
		return sum;
	}
	
//*****************************************************************************
}
